<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta charset="UTF-8">
	<title>优惠券列表</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />

    
<!-- 最新导入 -->
<script type="text/javascript" src="<c:url value='/template/new_muban/js/jquery-min-1.7.js'/>"></script>
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/font.css'/>">
<link rel="stylesheet" href="<c:url value='/template/new_muban/css/xadmin.css'/>">   
<script src="<c:url value='/template/new_muban/lib/layui/layui.js'/>" charset="utf-8"></script> 
<script type="text/javascript" src="<c:url value='/template/new_muban/js/xadmin.js'/>"></script>

 <!-- 富文本编辑器 -->
<script type="text/javascript" charset="utf-8" src="<c:url value='/ue/ueditor.config.js'/>"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/ue/ueditor.all.js'/>"> </script>



<!-- 标签 -->
<link rel="stylesheet" type="text/css" href="<c:url value='/template/lead_into/tags_input/css.css'/>" />
<script src="<c:url value='/template/lead_into/tags_input/tagsinput.js'/>" type="text/javascript" charset="utf-8"></script>
		
<style type="text/css">
	/*圆形头像  */
	/* #divcss5{ margin:10px auto}  */
	/* #divcss5 img{ border-radius:50%}  */
	.x-so input.layui-input {
    	width: 150px;
	}
	.layui-table img {
    	max-width: 200px;
	}
</style>
</head>
<body>
     <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">优惠券管理</a>
        <a>
          <cite>优惠券列表</cite></a>
      </span>
     <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
    </div>
    <div class="layui-fluid">
	            <div class="layui-row layui-col-space15">
	                <div class="layui-col-md12">
	                    <div class="layui-card">
            <div class="layui-card-body "><!-- onsubmit="return verifyDate();" -->
                             
                        </div> 
       <div class="layui-card-header">
        <button class="layui-btn" onclick="xadmin.open('新增优惠券','<c:url value='/preAddCoupon.do'/>')"><i class="layui-icon"></i>新增优惠券</button>
        <%-- <span class="x-right" style="line-height:40px">本页数据 ：${fn:length(AllShopUser)} 条   &nbsp;&nbsp;  共有数据 ：${page.allShopUserItem} 条</span> --%>
    </div> 
      <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form" id="">
        <thead>
          <tr>
           <!--  <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th> -->
	            <th style="width : 8%">ID</th>
	            <th>优惠券名称</th>
	            <th>优惠券价格</th>
	            <th>使用条件价格</th>
	            <th>开始日期</th>
	            <th>结束日期</th>
	            <th>创建日期</th>
	            <th>每人领取次数</th>
	            <th>优惠券数量</th>
	            <th>优惠券类型</th>
	            <th>操作</th>
            </tr>
        </thead>
        <tbody  id="x-img">
          <c:forEach items="${findAllCoupon}" var="coupon" varStatus="sm">
          	<tr>
          <!--   <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
            </td> -->
            <td>${sm.index+1}</td>
           
            <td>${coupon.c_title}</td>
           
            <td>${coupon.c_price}</td>
             <td>${coupon.c_pay_money}</td>
            <td>${coupon.c_btime}</td>
            <td>${coupon.c_etime}</td>
            <td>${coupon.c_creattime}</td>
            <td>${coupon.c_xz_count}</td>
            <td>
            	<c:if test="${coupon.c_counts == -1}">无限</c:if>
            	<c:if test="${coupon.c_counts != -1}">${coupon.c_counts}</c:if>
            </td>
             <td>
            	<c:if test="${coupon.c_type == 0}">通用</c:if>
            	<c:if test="${coupon.c_type == 1}">指定</c:if>
            </td>
            <td class="td-manage" style="text-align: center;">
	            <div class="layui-btn-group">
	<!--             暂不支持 -->
	            <button class="layui-btn layui-btn-sm" title="编辑" onclick="xadmin.open('${coupon.c_title}','<c:url value='/findCouponDetails.do?c_id=${coupon.c_id}'/>')" >
	               						 <span>编辑</span></button>
	     			<c:if test="${coupon.c_id != 2}">
	     				<c:if test="${coupon.c_id != 3}">
			     			<c:if test="${coupon.c_flag == 0 }">
			     				<button onclick="update_coupon_status_t(${coupon.c_id});" class="layui-btn layui-btn-sm layui-btn-danger" title="停用"><span>停用</span></button>
			     			</c:if>
			     			<c:if test="${coupon.c_flag == 1 }">
			     				<button onclick="update_coupon_status(${coupon.c_id});" class="layui-btn layui-btn-sm layui-btn-normal" title="启用"><span>启用</span></button>
			     			</c:if>	     				
	     				</c:if>
	     			</c:if>
	              <%-- <a class="layui-btn layui-btn-sm layui-btn-danger" title="删除" onclick="del_banner('${ticket.t_id}')" href="javascript:;">
	                <i class="layui-icon">&#xe640;</i>
	              </a> --%>
              </div>
            </td>
          </tr>
          
          </c:forEach>
          
          <tr>
        </tbody>
      </table>
     <%--  <div style="text-align: center;">
        <span style="border: 0px solid #E2E2E2;">${page.page_num}条每页/共${page.allShopUserItem}条  &nbsp;&nbsp; 第${page.number}页/共${page.sumNumber}页</span>
      </div> --%>
      <!-- 分页查询-->
    <%--   <div class="page">
        <div>
        <!-- 页码跳转 -->
        <c:if test="${page.sumNumber > 1}">
        	<input type="text" name="number" class="layui-input inputNum" style="display: inline; width: 50px;" onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();"  placeholder="页码"/>
         	<input type="button" class="layui-btn" onclick="checkNum(${page.sumNumber},'${page.start}','${page.end}','${page.s_name}','${page.s_contact}','${page.s_phone}','${page.openid}','${page.pay_status}','${page.page_num}','${page.tuijian_contact}');" value="跳转" /> 
       	</c:if>
       		<!-- 首页/上一页 -->
       		<c:if test="${page.number > 1}">
       			<a class="prev" href="<c:url value='/findAllShopUser.do?number=1&s_name=${page.s_name}&s_contact=${page.s_contact}&s_phone=${page.s_phone}&openid=${page.openid}&pay_status=${page.pay_status}&start=${page.start}&end=${page.end}&page_num=${page.page_num}&tuijian_contact=${page.tuijian_contact}'/>">首页</a>
				<a class="prev" href="<c:url value='/findAllShopUser.do?number=${page.number-1}&s_name=${page.s_name}&s_contact=${page.s_contact}&s_phone=${page.s_phone}&openid=${page.openid}&pay_status=${page.pay_status}&start=${page.start}&end=${page.end}&page_num=${page.page_num}&tuijian_contact=${page.tuijian_contact}'/>">&lt;&lt;</a>
			</c:if>
			<!-- 计算页码列表 -->
		<c:choose>
			使用c标签choose     when   otherwise   类似if else
			设置Var变量    默认在Page域中   本页面可直接使用
			<c:when test="${page.sumNumber<=5}">
				<c:set var="begin" value="1"/>
				<c:set var="end" value="${page.sumNumber}"/>
			</c:when>
			
			<c:otherwise>
				当总页数>5 通过计算得出begin和end 在第3位
				<c:set var="begin" value="${page.number-2}"/>
				<c:set var="end" value="${page.number+2}"/>
				头溢出
				<c:if test="${begin<1}">
					<c:set var="begin" value="1"/>
					<c:set var="end" value="${page.sumNumber}"/>
				</c:if>
				<!-- 为1显示5个 -->
				<c:if test="${begin==1}">
					<c:set var="begin" value="1"/>
					<c:set var="end" value="5"/>
				</c:if>
				尾溢出
				<c:if test="${end>page.sumNumber}">
					<c:set var="end" value="${page.sumNumber}"/>
					<c:set var="begin" value="${page.sumNumber-4}"/>
				</c:if>
			</c:otherwise>
		</c:choose>
		<!-- 循环遍历显示页码列表 -->
		<c:forEach var="i" begin="${begin}" end="${end}">
			<c:choose>
				用i表示页码   如果i等于当前页码   不能点击
				<c:when test="${i eq page.number}">
					<span class="current">${i}</span>
				</c:when>
				<c:otherwise>
					页码为超链接
					<a class="num" href="<c:url value='/findAllShopUser.do?number=${i}&s_name=${page.s_name}&s_contact=${page.s_contact}&s_phone=${page.s_phone}&openid=${page.openid}&pay_status=${page.pay_status}&start=${page.start}&end=${page.end}&page_num=${page.page_num}&tuijian_contact=${page.tuijian_contact}'/>">${i}</a>
				</c:otherwise>
			</c:choose>
		</c:forEach>
		<!-- 计算尾部页码 -->	
		<c:if test="${page.number < page.sumNumber}">
			<a class="next" href="<c:url value='/findAllShopUser.do?number=${page.number+1}&s_name=${page.s_name}&s_contact=${page.s_contact}&s_phone=${page.s_phone}&openid=${page.openid}&pay_status=${page.pay_status}&start=${page.start}&end=${page.end}&page_num=${page.page_num}&tuijian_contact=${page.tuijian_contact}'/>">&gt;&gt;</a>
			
			<a class="next" href="<c:url value='/findAllShopUser.do?number=${page.sumNumber}&s_name=${page.s_name}&s_contact=${page.s_contact}&s_phone=${page.s_phone}&openid=${page.openid}&pay_status=${page.pay_status}&start=${page.start}&end=${page.end}&page_num=${page.page_num}&tuijian_contact=${page.tuijian_contact}'/>">尾页</a>
		</c:if>	
          <!-- <a class="prev" href="">&lt;&lt;</a>
          <a class="num" href="">1</a>
          <span class="current">2</span>
          <a class="num" href="">3</a>
          <a class="num" href="">489</a>
          <a class="next" href="">&gt;&gt;</a> -->
          
        </div>
      </div> --%>
 </div>
      </div> 
    </div>
    <script>
    
	/*
	删除轮播图
	*/
	  function del_banner(b_id){
        layer.confirm('确认要删除吗？',function(index){
        	
            //发异步删除数据
        	$.ajax({
                type: "POST",
                async : false, // 注意此处需要yi步  
                url:  "<c:url value='/delBannerImage.do'/>",
                data: {"b_id":b_id},
                success: function(data){
                    if (data == 0) {
                    	layer.msg('删除失败!',{icon: 2,time:3000});      
                    } else  {
                   	 	layer.msg("删除成功", {icon: 6,time:500},function () {
                            //重新加载页面
                            location.reload();
                        });
 		           } 
               }
 	        }); 
        });
    }
    
	  /*
		启用门票
		*/
		  function update_coupon_status(c_id){
	        layer.confirm('确认要启用吗？',function(index){
	        	
	            //发异步删除数据
	        	$.ajax({
	                type: "POST",
	                async : false, // 注意此处需要yi步  
	                url:  "<c:url value='/uodateCouponStatus.do'/>",
	                data: {"c_id":c_id,"c_flag":0},
	                success: function(data){
	                    if (data == 0) {
	                    	layer.msg('启用失败,错误未知!',{icon: 2,time:3000});      
	                    } else  {
	                   	 	layer.msg("已启用", {icon: 6,time:500},function () {
	                            //重新加载页面
	                            location.reload();
	                        });
	 		           } 
	               }
	 	        }); 
	        });
	    }
		  /*
			停用门票
			*/
			  function update_coupon_status_t(c_id){
		        layer.confirm('确认要停用吗？',function(index){
		        	
		            //发异步删除数据
		        	$.ajax({
		                type: "POST",
		                async : false, // 注意此处需要yi步  
		                url:  "<c:url value='/uodateCouponStatus.do'/>",
		                data: {"c_id":c_id,"c_flag":1},
		                success: function(data){
		                    if (data == 0) {
		                    	layer.msg('停用失败,错误未知!',{icon: 2,time:3000});      
		                    } else  {
		                   	 	layer.msg("已停用", {icon: 6,time:500},function () {
		                            //重新加载页面
		                            location.reload();
		                        });
		 		           } 
		               }
		 	        }); 
		        });
		    }
   
   /*  
    layui.use('layer', function(){
        layer.msg('已删除!',{icon:1,time:10000},function(){
	parent.location.reload();
	let liId = $.cookie('liId');
	let liClass = $.cookie('liClass');
	console.log(liId);
	console.log(liClass);
	$('liId').attr("class","layui-nav-item layui-nav-iteme");
	console.log($(liId).attr("class"));
        	
        });  
    	
    });   */ 
    //时间
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){

              if($(obj).attr('title')=='启用'){

                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }
              
          });
      }

      /*用户-开通取消操作*/
      function member_stop_caozuo(obj,id){
              if($(obj).attr('title')=='停用'){
		          layer.confirm('确认要停用吗？',function(index){
	                //发异步把用户状态进行更改
	                $(obj).attr('title','开通')
	                $(obj).find('i').html('&#xe62f;');
	                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('未开通');
	                layer.msg('已停用!',{icon: 5,time:1000});
	                
	                
	                
	          	});
              }else{
            	 layer.confirm('确认要开通吗？',function(index){
	                $(obj).attr('title','停用')
	                $(obj).find('i').html('&#xe601;');
	                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已开通');
	                layer.msg('已开通!',{icon: 6,time:1000});
              	});
              }
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              //发异步删除数据
              $(obj).parents("tr").remove();
              layer.msg('已删除!',{icon:1,time:1000});
          });
      }

	
	
	
	

      function delAll (argument) {

        var data = tableCheck.getData();
  
        layer.confirm('确认要删除吗？'+data,function(index){
        
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }
    </script>

     
     <!-- 1 绿√  2 红X  3 黄?  4  灰锁  5  红哭脸  6 绿笑脸 7 黄!  --> 
    <!-- //页面跳转 -->
<script type="text/javascript">
	function checkNum(sumNumber,start,end,s_name,s_contact,s_phone,openid,pay_status,page_num,tuijian_contact){
		var num = $(".inputNum").val();
		//alert(sumNumber+"/"+num+"/"+s_name+"/"+s_contact+"/"+s_phone+"/"+openid+"/"+pay_status+"/"+start+"/"+end+"/"+page_num );
		if(!isNaN(num)){      
			//alert("是数字类型!");
			if (num>sumNumber) {
				//alert("超出查询范围");
				layer.alert('超出查询范围!!',{icon:2,time:2000});
				return false;
			} else if (num<1) {
				//alert("请输入正确的页码");
				layer.alert('请输入正确的页码!',{icon:2,time:2000});
				return false;
			} else {
		 		window.location.href = "<c:url value='/findAllShopUser.do?s_name="+s_name+"&s_contact="+s_contact+"&s_phone="+s_phone+"&number="+num+"&openid="+openid+"&pay_status="+pay_status+"&start="+start+"&end="+end+"&page_num="+page_num+"&tuijian_contact="+tuijian_contact+"'/>";
			}
		}else{      
			//alert("不是数字类型!");
			layer.alert('不是数字类型!',{icon:2,time:2000});
			return false;
		}
	}
/*
 * 验证 查询时间大小 
 */	
 function verifyDate() {
	var start = $("#start").val();
	var end = $("#end").val();
	//alert(start > end);
	if(start > end){
		//alert("开始日期不能大于结束日期!");
		layer.alert('开始日期不能大于结束日期!',{icon:2,time:3000});
		return false;		
	}
}

 <!-- 图片弹出层 -->
 layui.use('layer', function(){
     $ = layui.jquery;//jquery
   layer = layui.layer;//弹出层

   //以上模块根据需要引入
 	//轮播图弹出
     layer.ready(function(){ //为了layer.ext.js加载完毕再执行
       layer.photos({
         photos: '#x-img'
         //,shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机
       });
     });

 });
</script> 
<!-- 标签input -->
<script type="text/javascript">
function getinput(){
	alert($('#tagsinputval').val());
}     
</script>      
  </body>
</html>